// pages/Conveinfo/prefecon/prefecon.js
var app = getApp();
var ikz = require('../../Common/tools.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,//页数
    limit: 6,//每页条数
    conven_info: '',//优选信息
    tid:'',//分类id
    prodis: 'none',//底部提示是否显示
  },
  
  //跳转到详情页
  toContent: function (e) {
    var cid = e.currentTarget.dataset.cid;
    var data = {
      cid: cid,
    }
    ikz.nav('../content/content', 'n',data);
  },


  toTop: function () {
    wx.pageScrollTo({
      scrollTop: 0
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let isIphoneX = app.globalData.isIphoneX;
    this.setData({
      isIphoneX: isIphoneX
    })
    ikz.over(this);
    var that = this;
    var page = 1;
    var limit = that.data.limit;
    var data = {
      page: page,
      limit: limit,
    }
    var path = 'Conven/prefe';
    ikz.request(path, data, false, (res) => {
      console.log(res);
      console.log(res.data.conven_info);

      if (res.data.status == 'success') {
        that.setData({
          conven_info: res.data.conven_info,
          page: page,
        });
        ikz.hide(that);
      } else {
        wx.showModal({
          title: '加载失败',
          content: '请稍后重试！',
          showCancel: false
        })
      }

    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
       wx.showLoading({
         title: '刷新中...',
       });
       let isIphoneX = app.globalData.isIphoneX;
       this.setData({
         isIphoneX: isIphoneX
       })
       var that = this;
       var page = 1;
       var limit = that.data.limit;
       var data = {
         page: page,
         limit: limit,
       }
       var path = 'Conven/prefe';
       ikz.request(path, data, false, (res) => {
         if (res.data.status == 'success') {
           that.setData({
             conven_info: res.data.conven_info,
             page: page,
           });
           // 隐藏导航栏加载框  
           wx.hideNavigationBarLoading();
           // 停止下拉动作  
           wx.stopPullDownRefresh();
           wx.hideLoading()
         } else {
           wx.showModal({
             title: '加载失败',
             content: '请稍后重试！',
             showCancel: false
           })
         }

       });
      
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    wx.showLoading({
      title: '加载中',
    });
    var that = this;
    var page = that.data.page + 1;
    var old_info = that.data.conven_info;
    var tid = that.data.tid;
    that.setData({
      page: page,
    })
    var limit = that.data.limit;
    var data = {
      page: page,
      limit: limit,
      tid: tid,
    }
    var path = 'Conven/prefe';
    ikz.request(path, data, false, (res) => {
      console.log(res);
      if (res.data.status == 'success') {
        var new_info = res.data.conven_info;
        if (new_info.length) {
          var all_info = old_info.concat(new_info);
          var prodis = 'none';
        } else {
          var all_info = old_info;
          var prodis = 'block';
        }
        that.setData({
          conven_info: all_info,
          prodis: prodis,
        })
        
      } else {
        wx.showModal({
          title: '加载失败',
          content: '请稍后重试！',
          showCancel: false
        })
      }

    });
    wx.hideLoading();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})